extends MoveComponentBase
class_name BackForthComponent

@export var mover:Node2D
@export var forth_dir:Vector2
@export var back_dir:Vector2
@export var forth_time:float = 1
@export var back_time:float = 1
@export var forth_curve:Curve
@export var back_curve:Curve
var progress:float:
	set(value):
		progress = clampf(value,0,1)

var is_forth:bool = true

func _physics_process(delta: float) -> void:
	if !mover:
		return
	if is_forth:
		progress += delta/forth_time
		mover.position += forth_curve.sample(progress) * forth_dir
	else:
		progress += delta/back_time
		mover.position += back_curve.sample(progress) * back_dir
	if progress == 1:
		progress = 0
		is_forth = !is_forth
